home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / amivogl-1.03.lzh / vogl / examples / balls.c next >
Encoding:
C/C++ Source or Header  |  1994-07-16  |  2.8 KB  |  173 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include "gl.h"
  5. #include "device.h"
  6. #include "hershey.h"
  7. #else
  8. #include "vogl.h"
  9. #include "vodevice.h"
  10. #endif
  11.  
  12. #ifndef PI
  13. #define PI 3.1415926535
  14. #endif
  15.  
  16. #ifndef TC
  17. #include <math.h>
  18. #else
  19. extern double    sin(), cos();
  20. #endif
  21.  
  22. #define RADIUS 10.0
  23. #define    SPHERE    1L
  24.  
  25. /* ---------------------------------------------------------------------
  26.  * Prototypes:
  27.  */
  28. void makesphere(void);                                 /* balls.c         */
  29. int main(void);                                        /* balls.c         */
  30.  
  31. /* --------------------------------------------------------------------- */
  32.  
  33. /*
  34.  * makesphere
  35.  *
  36.  *    make a sphere object
  37.  */
  38. void makesphere(void)
  39. {
  40.     float    r, z;
  41.     int    i, a;
  42.  
  43.     makeobj(SPHERE);
  44.  
  45.         /*
  46.          * create the latitudinal rings
  47.          */
  48.         for (i = 0; i < 1800; i += 200) {
  49.             pushmatrix();
  50.                 rotate(i, 'y');
  51.                 circ(0.0, 0.0, RADIUS);
  52.             popmatrix();
  53.         }
  54.         
  55.         /*
  56.          * create the longitudinal rings
  57.          */
  58.         pushmatrix();
  59.             rotate(900, 'x');
  60.             for (a = -900; a < 900; a += 200) {
  61.                 r = RADIUS * cos((double)a * PI / 180.0);
  62.                 z = RADIUS * sin((double)a * PI / 180.0);
  63.                 pushmatrix();
  64.                     translate(0.0, 0.0, -z);
  65.                     circ(0.0, 0.0, r);
  66.                 popmatrix();    
  67.             }
  68.         popmatrix();
  69.  
  70.     closeobj();
  71. }
  72.  
  73. /*
  74.  * a demonstration of objects
  75.  */
  76. int main(void)
  77. {
  78.     short    val;
  79.  
  80.     winopen("balls");
  81.  
  82.     unqdevice(INPUTCHANGE);
  83.     qdevice(KEYBD);
  84.  
  85.     /*
  86.      * set up our viewing transformation
  87.      */
  88.     perspective(900, 1.0, 0.001, 500.0);
  89.     lookat(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0);
  90.  
  91.     color(BLACK);
  92.     clear();
  93.  
  94.     /*
  95.      * Call a routine to make the sphere object
  96.      */
  97.     makesphere();
  98.  
  99.     /*
  100.      * Now draw the sphere object scaled down. We use the pushmatrix
  101.      * and the popmatrix to preserve the transformation matrix so
  102.      * that only this sphere is drawn scaled.
  103.      */
  104.     color(CYAN);
  105.  
  106.     pushmatrix();
  107.         scale(0.5, 0.5, 0.5);
  108.         callobj(SPHERE);
  109.     popmatrix();
  110.  
  111.     /*
  112.      * now we draw the same sphere translated, with a different
  113.      * scale and color.
  114.      */
  115.  
  116.     color(WHITE);
  117.  
  118.     pushmatrix();
  119.         translate(0.0, -1.4 * RADIUS, 1.4 * RADIUS);
  120.         scale(0.3, 0.3, 0.3);
  121.         callobj(SPHERE);
  122.     popmatrix();
  123.  
  124.     /*
  125.      * and maybe a few more times....
  126.      */
  127.  
  128.  
  129.     color(RED);
  130.  
  131.     pushmatrix();
  132.         translate(0.0, RADIUS, 0.7 * RADIUS);
  133.         scale(0.2, 0.2, 0.2);
  134.         callobj(SPHERE);
  135.     popmatrix();
  136.  
  137.     color(GREEN);
  138.  
  139.     pushmatrix();
  140.         translate(0.0, 1.5 * RADIUS, -RADIUS);
  141.         scale(0.15, 0.15, 0.15);
  142.         callobj(SPHERE);
  143.     popmatrix();
  144.  
  145.     color(YELLOW);
  146.  
  147.     pushmatrix();
  148.         translate(0.0, -RADIUS, -RADIUS);
  149.         scale(0.12, 0.12, 0.12);
  150.         callobj(SPHERE);
  151.     popmatrix();
  152.  
  153.     color(BLUE);
  154.  
  155.     pushmatrix();
  156.         translate(0.0, -2.0*RADIUS, -RADIUS);
  157.         scale(0.3, 0.3, 0.3);
  158.         callobj(SPHERE);
  159.     popmatrix();
  160.  
  161.     hfont("times.rb");
  162.     ortho2(0.0, 1.0, 0.0, 1.0);
  163.     hcentertext(1);
  164.     htextsize(0.08, 0.15);
  165.     move2(0.8, 0.5);
  166.     htextang(-90.0);
  167.     hcharstr("I'm very ordinary!");
  168.  
  169.     qread(&val);
  170.  
  171.     gexit();
  172. }
  173.